package io.renren.modules.sys.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.Carmanage;
import io.renren.modules.sys.entity.dto.CarmanageSaveOrUpdateDto;
import io.renren.modules.sys.service.CarmanageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2022-09-05
 */
@RestController
@RequestMapping("/carmanage")
public class CarmanageController {
    @Autowired
    private CarmanageService carmanageService;
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = carmanageService.queryPage(params);
        return R.ok().put("page", page);
    }
    @RequestMapping("/save")
    public R save(@RequestBody CarmanageSaveOrUpdateDto saveOrUpdateDto){
        System.out.println("saveOrUpdateDto:::"+saveOrUpdateDto);
        Carmanage carmanage = new Carmanage();
        BeanUtils.copyProperties(saveOrUpdateDto,carmanage);
        carmanage.setCreateTime(new Date());
        carmanage.setUpdateTime(new Date());
        carmanageService.save(carmanage);
        return R.ok();
    }
    @RequestMapping("/info")
    public R info(@RequestParam Map<String, Object> params){
        Object id = params.get("id");
        Carmanage carmanage = carmanageService.getById((Serializable) id);
        return R.ok().put("car",carmanage);
    }
    @RequestMapping("/update")
    public R update(@RequestBody CarmanageSaveOrUpdateDto saveOrUpdateDto){
        Carmanage carmanage = new Carmanage();
        BeanUtils.copyProperties(saveOrUpdateDto,carmanage);
        carmanage.setCreateTime(new Date());
        carmanage.setUpdateTime(new Date());
        carmanageService.update(carmanage,new QueryWrapper<Carmanage>().eq("id",saveOrUpdateDto.getId()));
        return R.ok();
    }
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer id){
        carmanageService.removeById(id);
        return R.ok();
    }
    @RequestMapping("/findAllCarRand")
    public R findAllCarRand(){
       List<Carmanage> carmanages =  carmanageService.findAllCarRand();
       return R.ok().put("list",carmanages);
    }
}

